package dao;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

import utility.Util_Trading;

import databean.BidderBean;

public class GetBidderListDAO {
	
	public static List<BidderBean> getBidderListDAO() {
		
		Document response = Util_Trading.sendRequest("GetBidderList.txt", null);
				
		NodeList ids=response.getElementsByTagName("UserID");
		int len=ids.getLength();
		
		NodeList feedbackScores = response.getElementsByTagName("FeedbackScore");
		NodeList positiveFeedbackPercents = response.getElementsByTagName("PositiveFeedbackPercent");
		NodeList feedbackRatingStars = response.getElementsByTagName("FeedbackRatingStar");
		NodeList IDVerifieds = response.getElementsByTagName("IDVerified");
		NodeList eBayGoodStandings = response.getElementsByTagName("eBayGoodStanding");
		NodeList registrationDates = response.getElementsByTagName("RegistrationDate");
		NodeList sites = response.getElementsByTagName("Site");
		NodeList status = response.getElementsByTagName("Status");
		
		List<BidderBean> beans = new ArrayList<BidderBean>();
		
		for(int i=0;i<len;i++){
			
			BidderBean bean = new BidderBean();
			bean.setUserID(geti(ids,i));
			bean.setFeedbackScore(geti(feedbackScores,i));
			bean.setPositiveFeedbackPercent(geti(positiveFeedbackPercents,i));
			bean.setFeedbackRatingStar(geti(feedbackRatingStars,i));
			bean.setIDVerified(geti(IDVerifieds,i));
			bean.seteBayGoodStanding(geti(eBayGoodStandings,i));
			bean.setRegistrationDate(geti(registrationDates,i));
			bean.setSite(geti(sites,i));
			bean.setStatus(geti(status,i));
			beans.add(bean);
			
		}
		return beans;
	}
	
    private static String geti(NodeList list,int i){
    	return list.item(i).getChildNodes()
		.item(0).getNodeValue();
    }
	
}
 